﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Xml;
namespace Web.Views.Common
{
    public partial class TicketDetali : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //查询手机：http://www.yodao.com/smartresult-xml/search.s?type=mobile&q=13564370000

            //本询IP：http://www.yodao.com/smartresult-xml/search.s?type=ip&q=221.123.123.123

            //身份证：http://www.yodao.com/smartresult-xml/search.s?type=id&q=身份证号码

        }
        protected string GetMobileAddress(string mobie)
        {
            string add = "未找到归属地";
            try
            {
                string site = string.Format("http://www.yodao.com/smartresult-xml/search.s?type=mobile&q={0}", mobie);
                string xmlStr = GetValueFromWeb(site);
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmlStr);
                XmlNode node = doc.SelectSingleNode("//location");
                if (node != null)
                    add = node.InnerText;
                return add;
            }
            catch
            {
                return add;
            }
           
          
        }
        private string GetValueFromWeb(string url)
        {
            string html = null;
            WebRequest req = WebRequest.Create(url);
            WebResponse res = req.GetResponse();
            Stream stream = res.GetResponseStream();
            Encoding encode = Encoding.GetEncoding("gb2312");
            StreamReader sr = new StreamReader(stream, encode);

            char[] readbuffer = new char[256];
            int n = sr.Read(readbuffer, 0, 256);
            while (n > 0)
            {
                string str = new string(readbuffer, 0, n);
                html += str;
                n = sr.Read(readbuffer, 0, 256);
            }

            return html;
        } 
        #region 发送短信
        //        //发送短信
//        public void SendSms(string phoneNumber, string text)
//       {
//            string url;
//           url = string.Format(@"http://a.b.c.d/path/?user=username&password=password&phonenumber={0}&text={1}&charset=gb2312", phoneNumber, HttpUtility.UrlEncode(text));

//            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);

//            request.MaximumResponseHeadersLength = 10240;
//            request.Credentials = CredentialCache.DefaultCredentials;
//            request.Method = "GET";
//            request.Timeout = 60000;
//            WebResponse webRep = request.GetResponse();

//            Debug.WriteLine(webRep.Headers.ToString());
//            Debug.WriteLine(webRep.ResponseUri.OriginalString);
//16
//17            读取网页内容/不需要#region 读取网页内容/不需要
//18            // Obtain a 'Stream' object associated with the response object.
//19            Stream ReceiveStream = webRep.GetResponseStream();
//20
//21            Encoding encode = System.Text.Encoding.GetEncoding("gb2312");
//22
//23            // Pipe the stream to a higher level stream reader with the required encoding format. 
//24            StreamReader readStream = new StreamReader(ReceiveStream, encode);
//25            Console.WriteLine("\nResponse stream received");
//26            Char[] read = new Char[256];
//27
//28            // Read 256 charcters at a time.    
//29            int count = readStream.Read(read, 0, 256);
//30            Console.WriteLine("HTML\r\n");
//31
//32            while (count > 0) {
//33                // Dump the 256 characters on a string and display the string onto the console.
//34                String str = new String(read, 0, count);
//35                Console.Write(str);
//36                count = readStream.Read(read, 0, 256);
//37            }
//38
//39            Console.WriteLine("");
//40            // Release the resources of stream object.
//41            readStream.Close();
//42            #endregion
//43
//44            // Release the resources of response object.
//45            webRep.Close();
//46
        //47        }
        #endregion
    }
}
